package zero.tech.wsnet.node.service;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSONObject;

import zero.tech.core.data.Resp;
import zero.tech.core.data.RespCode;
import zero.tech.wsnet.data.CMD;
import zero.tech.wsnet.data.Message;
import zero.tech.wsnet.data.ReqNodeReportAnswer;
import zero.tech.wsnet.net.CacheClient;
import zero.tech.wsnet.node.NodeClient;
import zero.tech.wsnet.node.ReportProperties;
import zero.tech.wsnet.node.service.api.INodeService;

public class NodeServiceImpl implements INodeService {
	@Autowired
	private ReportProperties reportProperties;

	@Override
	public void nodeReportAnswer(NodeClient wsClient) {
		ReqNodeReportAnswer req = new ReqNodeReportAnswer();
		req.setGame_id(reportProperties.getGameId());
		req.setServer_node_key(reportProperties.getServerNodeKey());
		req.setIp(reportProperties.getServerNodeIp());
		req.setIn_ip(reportProperties.getServerNodeInip());
		req.setPort(reportProperties.getServerNodePort());
		req.setIn_port(reportProperties.getServerNodeInport());
		req.setConnect_count(CacheClient.clients.size());
		req.setContext_url(reportProperties.getContextUrl());
		wsClient.sendMessage(Message.build(CMD.COMMON_NODE_REPORT_ANSWER,
				Resp.build(RespCode.OK, "上报信息").setParam((JSONObject)JSONObject.toJSON(req))));
	}

}
